package com.help10000.rms.ui.activitys

import android.os.Bundle

import androidx.recyclerview.widget.LinearLayoutManager
import com.amir.common.beans.OrderItem
import com.amir.common.weight.SpaceItemDecoration
import com.help10000.rms.R
import com.help10000.rms.mvp.presenter.ServiceHisPresenter
import com.help10000.rms.mvp.view.ServiceHisView
import com.help10000.rms.ui.adapter.ServiceHisAdapter
import com.help10000.rms.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_service_his.*


/**
 * 服务历史记录
 */
class ServiceHistoryActivity : BaseActivity<ServiceHisPresenter, ServiceHisView>(), ServiceHisView {

    var Tel: String? = ""
    var orderList = mutableListOf<OrderItem>()
    var orderAdapter: ServiceHisAdapter? = null
    override fun getlayoutId(): Int {
        return R.layout.activity_service_his
    }

    override fun initView() {
        initRefreshLayout(refresh)
    }

    override fun initData(savedInstanceState: Bundle?) {
        downOnRefresh()
        Tel = intent.getStringExtra("Tel")
        val linearLayoutManager = LinearLayoutManager(mContext)
        rv_list.layoutManager = linearLayoutManager
        orderAdapter = ServiceHisAdapter(mContext, orderList, R.layout.item_order_layout)
        rv_list.adapter = orderAdapter
        rv_list.addItemDecoration(SpaceItemDecoration(0, 10))
    }

    override fun downOnRefresh() {
        super.downOnRefresh()
        mPresenter.PageNo = 1
        this.orderList.clear()
        mPresenter.getData(Tel)
    }

    override fun loadMore() {
        mPresenter.PageNo++

        super.loadMore()
    }

    override fun dataSuccess(orderList: MutableList<OrderItem>) {
        this.orderList.addAll(orderList)
        orderAdapter?.notifyDataSetChanged()

    }

    override fun createPresenter(): ServiceHisPresenter {
        return ServiceHisPresenter(this)
    }
}